package com.health.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;

public class DateConverterUtil implements Converter
{

	@Override
	public Object convert(Class type, Object value)
	{
		System.out.println("UtilDateConverter.value=" + value);
		if (!"".equals(value) && value instanceof Date)
		{
			return value;
		}

		Date d = null;
		if (!"".equals(value) && value instanceof String)
		{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			try
			{
				d = sdf.parse((String) value);
				return d;
			}
			catch (ParseException e)
			{
				e.printStackTrace();
			}
		}

		if (value instanceof Integer)
		{
			return (Integer) value;
		}
		return null;
	}

}
